package com.zzjson.quartz.cron;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.quartz.cron</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月04日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class CronSchedule {
    public static void main(String[] args) {
        JobDetail build = JobBuilder.newJob(CronJob.class).withIdentity("cron", "cron_group").build();
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("cronTrigger", "cronTriggerGroup").withSchedule(CronScheduleBuilder.cronSchedule("10/2 * * * * ? * ")).build();
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            scheduler = stdSchedulerFactory.getScheduler();
            scheduler.start();
            Date date = scheduler.scheduleJob(build, cronTrigger);
            System.out.println(date);
            //scheduler执行两秒后挂起
            scheduler.standby();

        } catch (SchedulerException e) {
            e.printStackTrace();
        }

    }

}